/*
 * COPYRIGHT. ShenZhen JiMi Technology Co., Ltd. 2017.
 * ALL RIGHTS RESERVED.
 *
 * No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
 * on any form or by any means, electronic, mechanical, photocopying, recording, 
 * or otherwise, without the prior written permission of ShenZhen JiMi Network Technology Co., Ltd.
 *
 * Amendment History:
 * 
 * Date                   By              Description
 * -------------------    -----------     -------------------------------------------
 * 2017年7月7日    Li.Shangzhi         Create the class
 * http://www.jimilab.com/
 */

package com.jimi.api.pay.controller;

import javax.servlet.http.HttpServletRequest;

import net.sf.oval.constraint.NotBlank;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.jimi.api.pay.IPayViewApi;
import com.jimi.api.pay.vo.PayInfoVo;
import com.jimi.dto.base.PageModel;
import com.jimi.dto.base.PageModel.Order;
import com.jimi.framework.base.BaseController;
import com.jimi.framework.bean.BeanUtil;
import com.jimi.framework.utils.ResultModel;
import com.jimi.samples.pay.api.IPayTokenApi;
import com.jimi.samples.pay.dto.input.PayTokenPageInputDto;
import com.jimi.samples.pay.dto.output.PayTokenOutputDto;

/**
 * @FileName PayController.java
 * @Description:
 *
 * @Date 2017年7月7日 上午10:22:51
 * @author Li.Shangzhi
 * @version 1.0
 */
@RestController
@RequestMapping(value = "/pay")
public class PayController extends BaseController implements IPayViewApi {

	@Autowired
	private IPayTokenApi payTokenApi;
	
	@Override
	@ResponseBody
	@RequestMapping(value = "/getPayList", params = { "method=jimi.samples.home.pay.list" }, produces = { "application/json" }, method = RequestMethod.GET)
	public ResponseEntity<ResultModel> getPayList(
			@NotBlank(message = "api.pageNum.invalid") @RequestParam(value = "pageNum", required = true) int pageNum,
			@NotBlank(message = "api.pageSize.invalid") @RequestParam(value = "pageSize", required = true) int pageSize,
			HttpServletRequest request) {
		PageModel pageModel = new PageModel();
		pageModel.setPage(pageNum);
		pageModel.setLimit(pageSize);
		pageModel.setOrderSort("createTime");
		pageModel.setOrder(Order.DESC);
		PageModel<PayTokenOutputDto> output = payTokenApi.findPage(new PayTokenPageInputDto(), pageModel);
		ResultModel result = new ResultModel();
		result.setResult(BeanUtil.convertBeanList(output.getItems(), PayInfoVo.class));
		return new ResponseEntity<>(result, HttpStatus.OK);
	}
}
